<template>
    <div class="common-layout">
        <el-container>
            <el-header>
                <!--条件查询-->
                <el-form :inline="true" :model="chaForm" class="demo-form-inline">  
                    <el-form-item label="签约日期">
                             <el-date-picker
                    v-model="chaForm.CreateStartTime"
                    type="date"
                    placeholder="年/月/日"
                    :size="size"
                />  ~  
                <el-date-picker
                    v-model="chaForm.CreateEndTime"
                    type="date"
                    placeholder="年/月/日"
                    :size="size"
                />
                    </el-form-item>&nbsp;&nbsp;
                    <el-form-item label="签约团队">
                         <el-select v-model="chaForm.Team" placeholder="请选择团队" style="width: 150px;">
                            <el-option value="0">请选择</el-option>
                            <el-option v-for="team in teamData" :key="team.teamID"
                            :label="team.teamName" :value="team.teamID"
                            ></el-option>
                         </el-select>
                    </el-form-item>&nbsp;&nbsp;
                    <el-form-item label="姓名">
                        <el-input v-model="chaForm.ResidentFiles_Name" placeholder="请输入姓名"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="getSignData()">查询</el-button>
                    </el-form-item>
                </el-form>
            </el-header>
            <el-main>
              <div class="mainBody">
                  <el-card style="width: 480px;margin-bottom: 2vw;margin-right:2vw;" shadow="always " v-for="item in tableData" :key="item.ncdSign_Id">
                    <template #header>
                    <div class="card-header" style="background-color: skyblue;color: white;">
                        <span>{{item.residentFiles_Name}}&nbsp;{{item.sex}}&nbsp;&nbsp;{{item.age}}</span>
                    </div>
                    </template>
                    <p>签约时间：{{ item.createTime}}</p>
                    <p>联系电话：{{item.phone}}</p>
                    <p>身份证号：{{item.idCard}}</p>
                    <p>签约周期：{{item.sign_StartTime}} ~ {{item.sign_EndTime}}</p>
                    <template #footer>慢病类型：{{item.manageNCD}}</template>
                </el-card>
              </div>
                  <!--分页-->
    <table style="margin: 15px auto;">
    <tbody>
        <tr>
            <!--总页数-->
            <td>
                <el-pagination
      v-model:current-page="page.pageIndex"
      v-model:page-size="page.pageSize"
      :page-sizes="[2, 4, 6, 8]"
      :background="true"
      layout=" total,slot,sizes"    
      :total="page.totalCount" prev-text="上一页" next-text="下一页"
    >
<span>每页{{ page.pageSize }}条,共{{ page.pageIndex }}/{{ page.totalPage }}行</span>
                </el-pagination>
            </td>
            <!--首页-->
            <td>
                <el-pagination
      v-model:current-page="page.pageIndex"
      v-model:page-size="page.pageSize"
      :page-sizes="[2, 4, 6, 8]"
      :background="true"
      layout=" solt,prev,pager,next"    
      :total="page.totalCount" prev-text="上一页" next-text="下一页">
      <button class="btn-prev" :disabled="page.pageIndex==1" @click="page.pageIndex=1">首页</button>
            </el-pagination>
            </td>
            <!--尾页-->
            <td>
                <el-pagination
      v-model:current-page="page.pageIndex"
      v-model:page-size="page.pageSize"
      :page-sizes="[2, 4, 6, 8]"
      :background="true"
      layout=" solt,jumper"    
      :total="page.totalCount" prev-text="上一页" next-text="下一页">
      <button class="btn-next" :disabled="page.pageIndex==page.totalPage" @click="page.pageIndex=page.totalPage">尾页</button>
            </el-pagination>
            </td>
        </tr>
    </tbody>
  </table>
           </el-main>
        </el-container>
    </div>
    <!--弹出框添加-->
    <!--添加患者签约信息-->

</template>
<script setup lang="ts">
import {  reactive, ref, onMounted, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useCounterStore } from '@/stores/counter'
import axios from 'axios'
import { ElMessage } from 'element-plus'
const apiUrl = import.meta.env.VITE_APP_API_URL;

    const store = useCounterStore()
    const router = useRouter()
    
    const chaForm = reactive({
      CreateStartTime: "",
      CreateEndTime: "",
      ResidentFiles_Name: "",
      ResidentFiles_Id: 0,
      Team: null,
      Doctor_Name: '',
      PageIndex: 1,
      PageSize: 15
    })

    const page = reactive({
      pageIndex: 1,
      pageSize: 15,
      totalCount: 0,
      totalPage: 0
    })

    const tableData = ref([])
    const teamData = ref([])

    const getTeamData = async () => {
      try {
        const res = await axios.get(apiUrl+'/T7/Sign/GetTeamSlect')
        teamData.value = res.data.data
      } catch (error) {
        ElMessage.error('获取团队数据失败')
      }
    }

    const getSignData = async () => {
      try {
        const res = await axios.get(apiUrl+"/T7/Sign/GetResidentFilesList", {
          params: {
            PageIndex: page.pageIndex,
            PageSize: page.pageSize,
            CreateStartTime: chaForm.CreateStartTime,
            CreateEndTime: chaForm.CreateEndTime,
            ResidentFiles_Name: chaForm.ResidentFiles_Name,
            ResidentFiles_Id: chaForm.ResidentFiles_Id,
            Team: chaForm.Team,
            Doctor_Name: chaForm.Doctor_Name,
          }
        })
        tableData.value = res.data.list
        page.totalCount = res.data.totalCount
        page.totalPage = res.data.totalPage
      } catch (error) {
        ElMessage.error('获取签约数据失败')
      }
    }

    watch(page, () => {
      getSignData()
    })

    onMounted(() => {
      getTeamData()
      getSignData()
    })



</script>
<style scoped>
    /* 全局样式规范 */
:root {
  /* 企业主色（建议使用品牌色） */
  --primary-color: #409eff;
  /* 辅助色 */
  --success-color: #67c23a;
  --warning-color: #f90;
  --danger-color: #f56c6c;
  --info-color: #909399;
  
  /* 字体规范 */
  --font-primary: "PingFang SC", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-size-base: 14px;
  --font-size-lg: 16px;
  --font-weight-medium: 500;
  
  /* 间距规范 */
  --padding-base: 16px;
  --margin-base: 12px;
  --line-height-base: 1.5;
  
  /* 表格样式 */
  --table-row-height: 44px;
}

/* 全局基础样式 */
.common-layout {
  font-family: var(--font-primary);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: #303133;
}

.el-container {
  min-height: 100vh;
}

.el-header {
  padding: var(--padding-base);
  background-color: #f5f7fa;
  border-bottom: 1px solid #ebedf0;
}

.el-main {
  padding: var(--padding-base 24px);
  background-color: #fff;
}
.mainBody{display: flex;flex-wrap: wrap;}
/* 表单样式优化 */
.demo-form-inline {
  display: flex;
  align-items: center;
  gap: var(--margin-base);
}

.el-form-item {
  margin-bottom: 0;
}

.el-input,
.el-select {
  height: 40px;
  border-radius: 4px;
}

/* 按钮样式规范（统一使用组件内置类型，避免内联样式） */
.el-button {
  font-size: var(--font-size-base);
  border-radius: 4px;
  padding: 0 16px;
}

.el-button.primary {
  background-color: var(--primary-color);
  border-color: var(--primary-color);
}

.el-button.success {
  background-color: var(--success-color);
  border-color: var(--success-color);
}

.el-button.warning {
  background-color: var(--warning-color);
  border-color: var(--warning-color);
}

.el-button.danger {
  background-color: var(--danger-color);
  border-color: var(--danger-color);
}

/* 表格样式优化 */
.el-table {
  margin-top: var(--margin-base);
  border-radius: 8px;
  overflow: hidden;
}

.el-table__header-wrapper {
  background-color: #f5f7fa;
}

.el-table__row {
  height: var(--table-row-height);
}

.el-table__cell {
  padding: 0 16px;
  border-bottom: 1px solid #ebedf0;
  font-size: var(--font-size-base);
}

.el-table--striped .el-table__body tr.el-table__row--striped {
  background-color: #f9fafc;
}

/* 状态标签样式 */
.el-tag {
  font-size: var(--font-size-base);
  padding: 4px 12px;
}

/* 弹窗样式优化 */
.el-dialog {
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.el-dialog__header {
  padding: var(--padding-base);
  background-color: #f5f7fa;
  border-bottom: 1px solid #ebedf0;
}

.el-dialog__title {
  font-size: var(--font-size-lg);
  font-weight: var(--font-weight-medium);
}

.el-dialog__body {
  padding: var(--padding-base 24px);
}

.el-form-item {
  margin-bottom: 20px;
}

/* 分页样式优化 */
.el-pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end; /* 建议右对齐，符合企业规范 */
}

.el-pagination__sizes {
  margin-right: var(--margin-base);
}

.el-pagination__editor {
  width: 60px;
  margin: 0 8px;
}

/* 操作按钮组样式 */
.el-table__fixed-right {
  padding-right: 16px; /* 固定列右侧间距 */
}

.table-operation {
  display: flex;
  gap: 8px;
}

/* 禁用状态样式 */
[disabled],
.disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.demo-date-picker {
  display: flex;
  width: 100%;
  padding: 0;
  flex-wrap: wrap;
}

.demo-date-picker .block {
  padding: 30px 0;
  text-align: center;
  border-right: solid 1px var(--el-border-color);
  flex: 1;
}

.demo-date-picker .block:last-child {
  border-right: none;
}

.demo-date-picker .demonstration {
  display: block;
  color: var(--el-text-color-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}

.demo-tabs > .el-tabs__content {
  padding: 32px;
  color: #6b778c;
  font-size: 32px;
  font-weight: 600;
}
.mainBody :deep(.el-card__header){background-color: darkblue !important;}
/* 响应式优化 */
@media (max-width: 768px) {
  .el-main {
    padding: var(--padding-base);
  }
  
  .el-table {
    font-size: 13px;
  }
}
</style>